<template>
    <div class="common-page page-org" v-loading.fullscreen="loading"></div>
</template>

<script>
    import mixin from "../mixin";
    import { string } from "../util";
    export default {
        name: "page-org",
        title: "组织架构",
        nodes: ["/menu/org"],
        childs: ["org-clients","org-depts"],
        mixins: [mixin],
        data: () => ({
            loading: false,
        }),
        methods: {
            destroy() {
                if (this.loading) return;
                return true;
            },
            init() {
                if (this.loading) return;
                this.loading = true;
                this.$root.$refs.navbar.init();
                this.plugins.user.call(async () => {
                    let res = await this.plugins.user.init();
                    if (res.code === 0) { }
                    return res;
                }).then((res) => {
                    this.loading = false;
                    this.$root.$refs.navbar.init();
                    if (res.code === 0) {
                        if (this.access(this.$route.name)) {
                            let name = this.$options.childs.find((name) => this.access(name));
                            if (name) this.$router.replace(name);
                        } else {
                            this.$router.replace("/home");
                        }
                    } else if (res.code === 2) {
                        this.$root.$refs.navbar.login();
                    } else {
                        this.plugins.modal.alert("页面加载失败", res.code + "：" + res.msg, "error").then(() => this.$router.replace("/home"));
                    }
                });
            },
        },
    };
</script>

<style lang="scss">
    .page-org {
        overflow: hidden;
    }
</style>